import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import { createPinia } from 'pinia'
import "@fortawesome/fontawesome-free/css/all.min.css";
import axios from "axios";
import qs from "qs";
import {
  getCurDate,
  setSessionStorage,
  getSessionStorage,
  removeSessionStorage,
  setLocalStorage,
  getLocalStorage,
  removeLocalStorage,
} from "./common.js";

// 创建 Vue 应用实例
const app = createApp(App);
const pinia = createPinia()

// 设置 axios 的基础 URL
axios.defaults.baseURL = "http://localhost:8080/api/";

// 配置全局属性
app.config.globalProperties.$axios = axios;
app.config.globalProperties.$qs = qs;
app.config.globalProperties.$getCurDate = getCurDate;
app.config.globalProperties.$setSessionStorage = setSessionStorage;
app.config.globalProperties.$getSessionStorage = getSessionStorage;
app.config.globalProperties.$removeSessionStorage = removeSessionStorage;
app.config.globalProperties.$setLocalStorage = setLocalStorage;
app.config.globalProperties.$getLocalStorage = getLocalStorage;
app.config.globalProperties.$removeLocalStorage = removeLocalStorage;

// // 全局路由守卫
// router.beforeEach((to, from, next) => {
//   let user = sessionStorage.getItem("user");
//   let b = sessionStorage.getItem("business");
//
//   // 需要登录验证的路由
//   const publicRoutes = [
//     "/",
//     "/index",
//     "/businessList",
//     "/businessInfo",
//     "/login",
//     "/register",
//   ];
//
//   if (!publicRoutes.includes(to.path)) {
//     if (!user && !b) {
//       // 使用 router.push 而不是直接 location.reload
//       next("/login");
//       // 如果需要强制刷新，可以在这里调用
//       // window.location.reload();
//       return;
//     }
//   }
//
//   next();
// });

// 使用路由并挂载应用
app.use(router);
app.use(pinia);
app.mount("#app");
